home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / seahaven / seahaven.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.7 KB  |  220 lines

  1. /*
  2.  * Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  * Author:  Terry Weissman
  19.  *          weissman@sgi.com
  20.  */
  21.  
  22. #define NeedFunctionPrototypes 1
  23.  
  24.  
  25. #include <X11/Xlib.h>
  26.  
  27. #ifndef NULL
  28. #define    NULL 0
  29. #endif
  30.  
  31. #ifdef MAIN
  32. #define global
  33. #else
  34. #define global extern
  35. #endif
  36.  
  37.  
  38. typedef class StackRec *Stack;
  39. typedef class CardRec *Card;
  40.  
  41. class CardRec {
  42.   public:
  43.     CardRec(int suit, int value, unsigned long fore, unsigned long back,
  44.         char *bitmap);
  45. //    Window getWindow();
  46.     Stack getStack();
  47.     int getSuit();
  48.     int getValue();
  49.     int getX();
  50.     int getY();
  51.     Stack getFoldedStack();
  52.     int getFoldedY();
  53.     void setLoc(int, int);
  54.     void raise();
  55.     void raiseAbove(Card);
  56.     void raiseBelow(Card);
  57.     void setStack(Stack);    // To be called only by StackRec::addCard
  58.     void highlight();
  59.     void repaint();
  60.   private:
  61.     int suit;
  62.     int value;
  63.     Window window;
  64.     int x, y;
  65.     Stack stack;
  66. };
  67.  
  68.  
  69. enum StackType {Single, Play, Done};
  70. enum AnimType {Normal, Animate, DontMove};
  71.  
  72. class StackRec {
  73.   public:
  74.     StackRec(int x, int y);
  75.     virtual void clear();
  76.     virtual int getX();
  77.     virtual int getY();
  78.     virtual Card getTopCard();
  79.     virtual Card getCardAbove(Card);
  80.     virtual Card popCard();
  81.     virtual Bool addCard(Card, AnimType animate = Normal);
  82.                 // Return TRUE iff successful.
  83.     virtual void repositionAll();
  84.     virtual int getStackingHeight();
  85.     virtual StackType getType();
  86.   protected:
  87.     int x, y;
  88.     int numcards;
  89.     Card cards[20];
  90.   private:
  91.     friend class Stack_Iterator;
  92. };
  93.  
  94. class Stack_Iterator {
  95.   public:
  96.     Stack_Iterator(Stack s) { stack = s; i = s->numcards; }
  97.     Card operator()() {
  98.       if (--i < 0)
  99.         return 0;
  100.       else
  101.         return stack->cards[i];
  102.     }
  103.   private:
  104.     Stack stack;
  105.     int i;    // current index
  106. };
  107.  
  108.  
  109. class ScoreRec {
  110.   public:
  111.     ScoreRec();
  112.     void repaint(Bool erasefirst = False);
  113.     void wonGame();
  114.     void lostGame();
  115.     void newGame();
  116.     Bool getGameWonOrLost();
  117.     void saveGameBegin();
  118.     void saveGameCard(Card);
  119.     void saveGameEnd();
  120.     void setMessage(char *);
  121.     Bool getNeedStartingGame();
  122.   private:
  123.     void printLine(char *, int value = 0, char *plural = "s");
  124.     Window window;
  125.     GC gc;
  126.     int wins, losses, streak, maxwinstreak, maxlosestreak;
  127.     int wonlast;        // Should be Bool, but this makes save easier
  128.     int curx, cury;
  129.     char savefile[512];
  130.     Card deck[52];
  131.     Bool woncurgame;
  132.     Bool lostcurgame;
  133.     char *message;
  134. };
  135.  
  136. typedef struct ScoreRec *Score;
  137.  
  138. class UndoListRec {
  139.   public:
  140.     UndoListRec();
  141.     void clear();
  142.     void add(Card, Stack);
  143.     void addBoundary();
  144.     void doUndo();
  145.     Bool isEmpty();
  146.   private:
  147.     int num;
  148.     int max;
  149.     Card *cards;
  150.     Stack *stacks;
  151. };
  152.  
  153. typedef class UndoListRec *UndoList;
  154.  
  155. static const int NUMSUITS = 4;
  156. static const int NUMVALUES = 13;
  157.  
  158. static const int CARDWIDTH = 64;
  159. static const int CARDHEIGHT = 96;
  160.  
  161. static const int GAMEWIDTH = 740;
  162. static const int GAMEHEIGHT = 708;
  163.  
  164. static const int NUMPLAYSTACK = 10;
  165. static const int NUMSINGLESTACK = 4;
  166. static const int CARDSPERPLAYSTACK = 5;
  167.  
  168.  
  169.  
  170. global char *progname;
  171. global Display *dpy;
  172. global Window toplevel;
  173. global int screen;
  174. global Colormap cmap;
  175. global Bool hascolor;
  176. global Bool hasgrey;
  177. global Card cards[NUMSUITS][NUMVALUES];
  178. global int speedup;
  179. global Score score;
  180. global XFontStruct *font;
  181. global unsigned long backpixel;
  182. global Bool inautoplay;
  183.  
  184. // From main.C
  185.  
  186. void Punt(char *);
  187.  
  188.  
  189. // From util.C
  190.  
  191. extern unsigned long GetColor(char *, char *, unsigned long);
  192. extern void GetInterestingEvent(XEvent *);
  193. extern Window CreateButtonWindow(char *, int, int, int, int *);
  194.  
  195.  
  196.  
  197. // From card.C
  198.  
  199. void CardInit();
  200. Bool CardHandleEvent(XEvent *);
  201.  
  202.  
  203. // From stack.C
  204.  
  205. void StackInit();
  206. void NewGame();
  207. void AutoMoves();
  208. int NumAvailableSingles();
  209. Stack GetAvailableSingle();
  210. Stack StackFromPoint(int x, int y);
  211. void DoUndo();
  212. void DoRedo();
  213. void DoRestart();
  214. void UndoBoundary();
  215. void LoadStacks(Card deck[52]);
  216. extern Stack playstack[NUMPLAYSTACK];
  217. extern Stack singlestack[NUMSINGLESTACK];
  218. extern Stack donestack[NUMSUITS];
  219. void DoAutoPlay();
  220.